﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO;

namespace WEB.Restrito.Visualizar
{
    public partial class frmPapel : PaginaBase 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!Page.IsPostBack)
                {
                    Header.Title = "Papel - Visualizar";

                    List<string> keys = new List<string>(Request.QueryString.AllKeys);

                    if (keys.Contains("ID"))
                    {
                        if (Request.QueryString["ID"] != null)
                        {
                            int id = int.Parse(Request.QueryString["ID"].ToString());
                            carregaForm(id);
                        }
                    }

                    mtv.SetActiveView(viewListagem);
                }
            }

            catch
            {
                Response.Redirect("~\\Login\\Login.aspx");
            }
        }

        #region Funções
        public void carregaForm(int id)
        {
            lblErro.Text = string.Empty;
            lblSucesso.Text = string.Empty;
            lblAlerta.Text = string.Empty;

            try
            {
                Papel obj = new Papel();

                obj = PapelDAO.Selecionar(UsuarioLogado.eventoID, id);

                if (obj != null)
                {
                    txtID.Text = obj.ID.ToString();
                    txtDescricao.Text = obj.descricao;

                }
            }
            catch (Exception ex)
            {
                lblErro.Text = ex.Message;
            }
        }
        #endregion

        #region Eventos do Formulario
        protected void btnVoltar_Click(Object sender, EventArgs e)
        {
            Response.Redirect("~/Restrito/Pesquisar/frmPapel.aspx");
        }
        #endregion
    }
}